package com.z.controller;


import com.z.pojo.Goods;
import com.z.pojo.PageBean;
import com.z.service.GoodsService;
import com.z.service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/manage/adminfindgoodspage.do")
public class FindGoodsPageServlet extends HttpServlet {
    private GoodsService goodsService = new GoodsServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String tid = req.getParameter("tid");
        String nowpage = req.getParameter("nowpage");
        String eachpage = req.getParameter("eachpage");
        String ordurl = String.valueOf(req.getRequestURL());

        String url = ordurl+"?"+(req.getQueryString()==null?"":req.getQueryString());
        System.out.println(url.indexOf("&nowpage"));
        if(url.indexOf("&nowpage")>-1){
            url = url.substring(0,url.indexOf("&nowpage"));
        }
        System.out.println(url);

        if(nowpage == null||"".equals(nowpage)){
            nowpage ="1";
        }
        if(eachpage == null||"".equals(eachpage)){
            eachpage ="6";
        }

        PageBean<Goods> pb =null;

        pb = goodsService.goodsFormType(Integer.valueOf(nowpage), Integer.valueOf(eachpage), null);
        System.out.println(pb);
        pb.setUrl(url);

        req.setAttribute("pb",pb);
        req.getRequestDispatcher("/manageGoods").forward(req,resp);
    }
}
